package com.jt.controller;

import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
//@RestController 程序不会执行视图解析器的配置
@Controller
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("findAll")
    public String findAll01(Model Model){
        //查询业务数据
        List<User> userList = userService.findAll();
        //传递数据
        Model.addAttribute("userList",userList);
        return "userList";//需要在yml中配置解析器(前缀后缀)
    }


    @RequestMapping("toAjax")
    public String findAll02(){
        return "ajax";//需要在yml中配置解析器(前缀后缀)
    }
    /**
     * 接收ajax请求: /findAjax
     * 返回:list<User>
     */
    @RequestMapping("findAjax")
    @ResponseBody
    public List<User> findAjax(){
        return userService.findAll();
    }
}
